<?php
/**
* method calls wrapper
* @author J.Ducastel <fredbird@fredbird.org>
* @version
*/
class ooXmlRpcMethodCall {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
    /**
    *
    * @access
    */
    function ooXmlRpcMethodCall() {
        $this->__construct();
    }/**/

    /**
    *
    * @access
    */
    function __construct() {
        $this->params=&new ooXmlRpcParams();
    }/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
    /**
    * sets content from xml string
    * @param string $xml
    * @access public
    * @return bool
    */
    function setFromXml($xml) {
        // creating domDocument instance
        if (!$domDocument=&domxml_open_mem($xml)) {
            return false;
        }
        // building
        $callNode=new ooXmlRpcDomNode($domDocument);
        //$deb=&wak::getservice('wakdebug');
        // setting method name
        if (!$nodes=$callNode->getxpathnodes('/methodCall/methodName/text()')) {
            return false;
        }
        $this->name=$nodes[0]->getContent();
        // getting params
        // $this->params=&new
        if ($nodes=$callNode->getxpathnodes('/methodCall/params')) {
            //echo $deb->vardump($nodes);
            //$pNode=&new ooXmlRpcDomNode($nodes[0]);
            $this->params->setFromNode($nodes[0]);
        }
        //$this->params=&new domXmlRpcParams();
        return true;
    }/**/

    /**
    * returns full methodName
    * @param
    * @access public
    * @return
    */
    function getName() {
        return $this->name;
    }/**/

    /**
    * sets methodName
    * @param string $name
    * @access public
    * @return
    */
    function setName($name) {
        if (!is_string($name))
            return false;
        $this->name=$name;
        return true;
    }/**/

    /**
    * returns method part of methodname (after the point='.')
    * @param
    * @access public
    * @return string|false
    */
    function getMethod() {
        if (!eregi('([a-z][a-z0-9]*)$',$this->name,$result))
            return false;
        return $result[1];
    }/**/

    /**
    * returns service part of methodname (before the point='.')
    * @access public
    * @return string|false
    */
    function getServiceName() {
        if (!eregi('^([a-z][a-z0-9]*)\.',$this->name,$result))
            return false;
        return $result[1];
    }/**/

    /**
    * return call's domXmlRpcParams instance
    * @param
    * @access public
    * @return domXmlRpcParams
    */
    function & getParams() {
        return $this->params;
    }/**/

    /**
    * return content as xml
    * @param
    * @access public
    * @return string
    */
    function getXml() {
        // get own, root node
        if (!$rootNode=&$this->getNode())
            return false;
        // append name
        $nameNode=$rootNode->makeChild('methodName');
        $nameNode->setContent($this->name);
        // append params
        $this->params->appendToNode($rootNode);
        // append content
        //if (!$this->content)
            //return false;
        //$this->content->appendToNode($rootNode);
        // build and return xml
        $doc=$rootNode->getDomDoc();
        return $doc->dump_mem(1);
    }/**/

    /**
    *
    * @param
    * @access public
    * @return
    * /
    function () {

    }/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
    /**
    * @var type desc
    */
    var $name; // methodName
    var $params; // ooXmlRpcParams instance
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
/**
    * build and return ooXmlRpcNode for content dom manipulation
    * @param
    * @access protected
    * @return ooxmlrpcnode
    */
    function & getNode() {
        $node=false;
        $baseXml='<?xml version="1.0" encoding="utf-8"?><methodCall />';
        if (!$dom=&domxml_open_mem($baseXml))
            return $node;
        $doc=&new ooXmlRpcDomNode($dom);
        $roots=&$doc->getxpathnodes('/*');
        $node=$roots[0];

        return $node;
    }/**/
}
?>
